import React from 'react';
import { SET_ANALYTICS_REQ_PARAMS, SET_SELECTED_COUNT_DAY } from '../../../redux/constants/analytics'
import Select from "react-select";
import { reqParamsData } from '../../../helpers/utils'

const SelectDay = (props) => {

  const options = [
    { value: 7, label: '7 дней' },
    { value: 14, label: '14 дней' },
    { value: 30, label: '30 дней' },
    { value: 90, label: '90 дней' }
  ]

  const handleChange = selectedOption => {
    props.setData(
      SET_ANALYTICS_REQ_PARAMS,
      {
        ...reqParamsData(selectedOption.value),
        "limit": selectedOption.value
      }
    );

    props.setData(
      SET_SELECTED_COUNT_DAY,
      selectedOption
    );
  };

  return (
    <Select
      className={`input-dark-bg ${props.className}`}
      classNamePrefix="dark_select"
      defaultValue={props.selectedCountDay}
      name="color"
      options={options}
      onChange={handleChange}
    />
  )
};


export default SelectDay
